import { SET_ORDER_TAB, SET_ORDER_PAY, SET_ORDER_NUMBER, SET_ORDER, SET_ORDER_ADDRESS } from "../actionType"
import { IAction } from "../../interface"

const initState: any = {
    tab: '蛋糕',
    order: {
        goods: [],
        total: '',
        order_id: '',
    },
    order_address: {
        city: '',
        town: '',
        contacts: '',
        phone: '',
    },
    orderTab: 0,
}

export const orderReducer = (state = initState, action: IAction) => {
    const { type, payload } = action
    switch (type) {
        case SET_ORDER_PAY:
            return { ...state, pay: payload }
            break;
        case SET_ORDER_NUMBER:
            return { ...state, order_id: payload }
            break;
        case SET_ORDER_ADDRESS:
            return { ...state, order_address: payload }
            break;
        case SET_ORDER:
            return { ...state, order: payload }
            break;
        case SET_ORDER_TAB:
            return { ...state, orderTab: payload }
            break;
        default:
            return state
    }
}